<!-- head -->
{include file='public/head' /}
<!-- head -->

<!-- left -->
{include file='public/left' /}
<!-- left -->

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            管理后台
            <small>1.0.0</small>
        </h1>
        <ol class="breadcrumb">
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-sm-12">
                <div class="box box-default">
                    <div class="box-header with-border">
                        <h3 class="box-title">添加房抵贷</h3>
                    </div>
                    <form class="form-horizontal" id="form" action="{:url('admin/house/postinsert','','')}">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="name" class="col-sm-2 control-label">贷款名称</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="name" name="name" placeholder="贷款名称">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="description" class="col-sm-2 control-label">贷款描述</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="description" name="description" placeholder="贷款描述">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="money" class="col-sm-2 control-label">贷款金额</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="money" name="money" placeholder="贷款金额，如5-10万输入5-10">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="month" class="col-sm-2 control-label">贷款期限</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="month" name="month" placeholder="贷款期限，如6-12个月输入6-12，1-10年输入12-120">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="lixi" class="col-sm-2 control-label">贷款利息</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="lixi" name="lixi" placeholder="贷款利息">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="speed" class="col-sm-2 control-label">放款速度</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="speed" name="speed" placeholder="放款速度，如1-3天输入1-3">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="payment" class="col-sm-2 control-label">还款方式</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="payment" name="payment" placeholder="还款方式">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="img" class="col-sm-2 control-label">图片</label>
                                <div class="col-sm-10">
                                    <input type="file" class="form-control" id="img" name="img">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="content" class="col-sm-2 control-label">内容</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" id="content" name="content" placeholder="内容"></textarea>
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="text-align:right;">
                            <button type="button" class="btn btn-sm btn-default" id="resetForm">清空</button>&nbsp;
                            <button type="button" class="btn btn-sm btn-primary" id="saveForm">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<line href="__STATIC__/bootstrap-fileinput/css/fileinput.css" type="text/css" rel="stylesheet" />
<script src="__STATIC__/bootstrap-fileinput/js/fileinput.js" type="text/javascript"></script>
<script src="__STATIC__/bootstrap-fileinput/js/locales/zh.js" type="text/javascript"></script>
<script type="text/javascript">

    var imgName = '';

    $("#img").fileinput({
        language : 'zh',
        showRemove: false,
        showUpload: true,
        showClose: false,
        showPreview: false,
        allowedFileTypes: ['image'],
        allowedFileExtensions : ['jpg', 'jpeg', 'png', 'gif'],
        uploadUrl: '{:url("admin/public/uploadimg","","")}',
        uploadExtraData: {
            'folder': 'house',
        },
    });

    $("#img").on("fileuploaded", function (event, data, previewId, index) {
        var result = data.response;
        if (result.status == 1) {
            imgName = result.data;
        } else {
            showAlert('提示', result.info, null);
        }
    });
</script>

<script src="__STATIC__/kindeditor/kindeditor-all-min.js" type="text/javascript"></script>
<script src="__STATIC__/kindeditor/lang/zh-CN.js" type="text/javascript"></script>
<script type="text/javascript">
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('#content', {
            minHeight: 200,
            resizeType : 1,
        });
    });
</script>

<script type="text/javascript">

    $(function(){
        $('#resetForm').click(function(){
            $('#name').val('');
        });

        $('#saveForm').click(function(){

            var name = $.trim($('#name').val());
            if (name == '') {
                $('#name').parents('.form-group').addClass('has-error');
                $('#name').parent().find('.help-block').html('请输入贷款名称');
                return false;
            }

            var description = $.trim($('#description').val());
            if (description == '') {
                $('#description').parents('.form-group').addClass('has-error');
                $('#description').parent().find('.help-block').html('请输入贷款描述');
                return false;
            }

            var money = $.trim($('#money').val());
            if (money == '') {
                $('#money').parents('.form-group').addClass('has-error');
                $('#money').parent().find('.help-block').html('请输入贷款金额');
                return false;
            }

            var month = $.trim($('#month').val());
            if (month == '') {
                $('#month').parents('.form-group').addClass('has-error');
                $('#month').parent().find('.help-block').html('请输入贷款期限');
                return false;
            }

            var lixi = $.trim($('#lixi').val());
            if (lixi == '') {
                $('#lixi').parents('.form-group').addClass('has-error');
                $('#lixi').parent().find('.help-block').html('请输入月利息');
                return false;
            }

            var speed = $.trim($('#speed').val());
            if (speed == '') {
                $('#speed').parents('.form-group').addClass('has-error');
                $('#speed').parent().find('.help-block').html('请输入放款速度');
                return false;
            }

            var payment = $.trim($('#payment').val());
            if (payment == '') {
                $('#payment').parents('.form-group').addClass('has-error');
                $('#payment').parent().find('.help-block').html('请输入还款方式');
                return false;
            }

            if (imgName == '') {
                $('#img').parents('.form-group').addClass('has-error');
                $('#img').parents('.form-group').find('.help-block').html('请上传图片');
            }

            editor.sync();
            content = $('#content').val();
            if (content == '') {
                $('#content').parents('.form-group').addClass('has-error');
                $('#content').parent().find('.help-block').html('请输入内容');
            }

            $.ajax({
                url: $('#form').attr('action'),
                type: 'POST',
                data: {
                    'name': name,
                    'description': description,
                    'money': money,
                    'month': month,
                    'lixi': lixi,
                    'speed': speed,
                    'payment': payment,
                    'img': imgName,
                    'content': content
                },
                dataType: 'JSON',
                success: function(data) {
                    if (data.status == 1) {
                        window.location.href = "{:url('admin/house/index','','')}";
                    } else {
                        showAlert('提示', data.info, null);
                    }
                }
            });
        });

        $('#creditcate_id').focus(function(){
            if ($('#creditcate_id').parents('.form-group').hasClass('has-error')) {
                $('#creditcate_id').parents('.form-group').removeClass('has-error');
                $('#creditcate_id').parent().find('.help-block').html('');
            }
        });

        $('#creditjob_id').focus(function(){
            if ($('#creditjob_id').parents('.form-group').hasClass('has-error')) {
                $('#creditjob_id').parents('.form-group').removeClass('has-error');
                $('#creditjob_id').parent().find('.help-block').html('');
            }
        });

        $('#name').focus(function(){
            if ($('#name').parents('.form-group').hasClass('has-error')) {
                $('#name').parents('.form-group').removeClass('has-error');
                $('#name').parent().find('.help-block').html('');
            }
        });

        $('#description').focus(function(){
            if ($('#description').parents('.form-group').hasClass('has-error')) {
                $('#description').parents('.form-group').removeClass('has-error');
                $('#description').parent().find('.help-block').html('');
            }
        });

        $('#money').focus(function(){
            if ($('#money').parents('.form-group').hasClass('has-error')) {
                $('#money').parents('.form-group').removeClass('has-error');
                $('#money').parent().find('.help-block').html('');
            }
        });

        $('#month').focus(function(){
            if ($('#month').parents('.form-group').hasClass('has-error')) {
                $('#month').parents('.form-group').removeClass('has-error');
                $('#month').parent().find('.help-block').html('');
            }
        });

        $('#lixi').focus(function(){
            if ($('#lixi').parents('.form-group').hasClass('has-error')) {
                $('#lixi').parents('.form-group').removeClass('has-error');
                $('#lixi').parent().find('.help-block').html('');
            }
        });

        $('#speed').focus(function(){
            if ($('#speed').parents('.form-group').hasClass('has-error')) {
                $('#speed').parents('.form-group').removeClass('has-error');
                $('#speed').parent().find('.help-block').html('');
            }
        });

        $('#payment').focus(function(){
            if ($('#payment').parents('.form-group').hasClass('has-error')) {
                $('#payment').parents('.form-group').removeClass('has-error');
                $('#payment').parent().find('.help-block').html('');
            }
        });

        $('#img').focus(function(){
            if ($('#img').parents('.form-group').hasClass('has-error')) {
                $('#img').parents('.form-group').removeClass('has-error');
                $('#img').parents('.form-group').find('.help-block').html('');
            }
        });

        $('#content').focus(function(){
            if ($('#content').parents('.form-group').hasClass('has-error')) {
                $('#content').parents('.form-group').removeClass('has-error');
                $('#content').parent().find('.help-block').html('');
            }
        });

    });

</script>

<!-- right -->
{include file='public/right' /}
<!-- right -->

<!-- foot -->
{include file='public/foot' /}
<!-- foot -->
